package com.thinkgem.jeesite.modules.ta.util;

import java.io.InputStream;
import java.sql.*;

/**
 * @作者 王建明
 * @创建日期 13-10-7
 * @创建时间 下午12:32
 * @版本号 V 1.0
 */
public class DataBaseUtil {
	public static InputStream getImageStreamFromDataBase(String id) {
		Connection conn = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn = DriverManager
					.getConnection(
							"jdbc:oracle:thin:@192.168.253.201:1521:orcl",
							"jsdb", "ok");
			Statement stmt = conn.createStatement();
			// String sql = "select s.signpic signpic from"
			// + " st_department"
			// + " d,st_user_department ud,st_user u,st_user_sign s where"
			// + " u.userid ="
			// +
			// " s.userid and d.departid = ud.order_id and u.userid=ud.userid";
			String sql = "select signpic from st_user_sign where userid= '"
					+ id + "'";

			ResultSet rs = stmt.executeQuery(sql);
			if (rs.next()) {
				return rs.getBinaryStream("signpic");
			}
			try {
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		} catch (Exception e) {
			System.out.println("出现异常: " + e.getMessage());
		} finally {
			// try {
			// if (conn != null)
			// conn.close();
			// } catch (SQLException e) {
			// e.printStackTrace();
			// }
		}
		return null;
	}
}